/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * 
 * Project Name:assign-tracer
 * Create Time: 2016年2月24日 下午8:57:09
 */
package com.lenovo.lmrp.server.assigntracer.util.grap;

import com.google.inject.Inject;
import com.lenovo.sdc.framework.util.AttributeBean;

/**
 * 
 * @author songyz
 * @version $Id: GrapFactory.java, v 0.1 2016年2月24日 下午8:57:09 songyz Exp $
 */
public class GrabFactory {

	private static final String TICKET_GRAB_STRATEGY = "ticket.grab.strategy";// 抢单策略
	public static int GRAB_CACHE_TIME;// 抢单策略的缓存时间
	public static Long GRAB_PERIOD;// 随机抢单策略的随机周期

	private static AttributeBean params;

	@Inject
	public GrabFactory(AttributeBean params) {
		GrabFactory.params = params;
		GRAB_PERIOD = (long) params.getAttribute("ticket.grab.period", 1000 * 30);
		GRAB_CACHE_TIME = params.getAttribute("ticket.cache.time", 60 * 30);
	}

	public static IGrab getIGrab() {
		String name = params.getAttribute(TICKET_GRAB_STRATEGY, "fcfs");
		if ("fcfs".equalsIgnoreCase(name)) {
			return new FCFSGrab();
		} else if ("random".equalsIgnoreCase(name)) {
			return new RandomGrab();
		}
		return null;
	}

}
